<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>路由入门案例</title>
	</head>
	<body>
		<div id="app">
			<!-- 2.添加路由链接
				router-link:vue会将标签解析为a标签 -->
				<router-link to="/shopping">商场</router-link>
				<router-link to="/zoo">动物园</router-link>
				<!-- 3.定义路由占位符 当用户点击路由时,在该位置展现页面 -->
				<router-view></router-view>
		</div>
		<!-- 定义商场组件 -->
		<template id="shoppingTem">
			<div>
				<h1>我是商场组件</h1>
				<router-link to="shopping/shoe">鞋店</router-link>
				<router-link to="/shopping/phone">手机店</router-link>
				<router-view></router-view>
			</div>
		</template>
		<!-- 1.引入js -->
		<script src="../js/vue.js"></script>
		<script src="../js/vue-router.js"></script>
		<script>
			// 4.定义组件变量
			const shopping = {
				template:"#shoppingTem"
			}
			const zoo = {
				template:'<h1>我是动物园组件</h1>'
			}
			const shoe = {
				template : "<h1>我是鞋店</h1>"
			}
			
			const phone = {
				template : "<h1>我是手机店</h1>"
			}
			
			// 5.配置路由规则
			//如果需要嵌套 则使用关键字children
			const router = new VueRouter({
				//定义规则
				routes:[
					{path:'/shopping',component:shopping,
						children:[
							{path:'/shopping/shoe',component:shoe},
							{path:'/shopping/phone',component:phone}
						]
					},
					{path:'/zoo',component:zoo}
				]
			})
			
			// 6.将路由组件挂载到
			const app = new Vue({
				el:"#app",
				router
				
			})
		</script>
	</body>
</html>
